package com.example.jqying.androiddemo.vistorPattern;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;

import com.example.jqying.androiddemo.R;
import com.example.jqying.androiddemo.vistorPattern.data.AccountBook;
import com.example.jqying.androiddemo.vistorPattern.data.ConsumeBill;
import com.example.jqying.androiddemo.vistorPattern.data.IncomeBill;
import com.example.jqying.androiddemo.vistorPattern.vistor.Boss;
import com.example.jqying.androiddemo.vistorPattern.vistor.CPA;
import com.example.jqying.androiddemo.vistorPattern.vistorInterface.IAccountBookView;
import com.example.jqying.androiddemo.vistorPattern.vistorInterface.IBill;

public class VistorActivity extends AppCompatActivity {


    private TextView tv_boss,tv_cpa;

    private IBill consume1,consume2,consume3,consume4,consume5,consume6,consume7;
    private IBill income1,income2,income3,income4,income5,income6,income7;
    private AccountBook accountBook;

    private IAccountBookView boss,cpa;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_vistor);
        //创建账单
        consume1 = new ConsumeBill("支出",100);
        consume2 = new ConsumeBill("支出",200);
        consume3 = new ConsumeBill("支出",300);
        consume4 = new ConsumeBill("支出",400);
        consume5 = new ConsumeBill("支出",500);
        consume6 = new ConsumeBill("支出",600);
        consume7 = new ConsumeBill("支出",700);

        income1 = new IncomeBill("收入",100);
        income2 = new IncomeBill("收入",200);
        income3 = new IncomeBill("收入",300);
        income4 = new IncomeBill("收入",400);
        income5 = new IncomeBill("收入",500);
        income6 = new IncomeBill("收入",600);
        income7 = new IncomeBill("收入",700);

        //添加到账本
        accountBook = new AccountBook();

        accountBook.add(consume1);
        accountBook.add(consume2);
        accountBook.add(consume3);
        accountBook.add(consume4);
        accountBook.add(consume5);
        accountBook.add(consume6);
        accountBook.add(consume7);

        accountBook.add(income1);
        accountBook.add(income2);
        accountBook.add(income3);
        accountBook.add(income4);
        accountBook.add(income5);
        accountBook.add(income6);
        accountBook.add(income7);

        //访问者
        boss = new Boss();
        cpa = new CPA();
        accountBook.show(boss);
        accountBook.show(cpa);


        //显示
        tv_boss = (TextView)findViewById(R.id.tv_boss);
        tv_cpa = (TextView)findViewById(R.id.tv_CPA);

        tv_cpa.setText(((Boss)boss).getResult());
        tv_boss.setText(((CPA)cpa).getResult());

    }
}
